package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param orders
     */
    void insert(Orders orders);

    Page<Orders> select(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select  * from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 查询订单各个状态的数量
     * @return
     */
    @Select("select status,count(*) as total_count from orders group by status ")
    List<Map<String, Object>> getOrderStatusCount();

    void updateOrderStatus(Long id,Integer status,String rejectionReason,String cancelReason);

    /**
     * 查询超时未支付订单
     * @param
     * @param
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{time} ")
    List<Orders> selectOrderTimeOutAndStatus(Integer status, LocalDateTime time);

    /**
     * 更新订单状态
     * @param item
     */
    void updateOrders(Orders item);

    /**
     * 根据条件统计用户数量
     * @param map
     * @return
     */
    Integer getCount(Map map);

    /**
     * 根据条件统计订单数量
     * @param map
     * @return
     */
    Integer getOrderCount(Map map);
}
